package functions;

public class PolynTerm extends FunctionIF implements Cloneable
{
	public PolynTerm(double c , double ex)
	{
		coff= c;
		expon = ex;
	}
	
	@Override
	protected Object clone() 
	{
		return new PolynTerm(coff, expon);
	}
	@Override
	public String toString()
	{
		if(expon == 0)
			return coff+"";
		else
			if(expon == 1)
				return coff+"*x";
		
		return coff+"*x^"+expon;
	}

	@Override
	public double eval(double x)
	{
		return coff * Math.pow(x, expon);
	}

	@Override
	public FunctionIF diff()
	{
		return new PolynTerm(coff * expon,expon - 1);
	}
}
